package com.pet.server.ext;

import java.util.HashMap;
import java.util.Map;

public class UriMeta {

	private static final String pack="com.pet.server.ext.action.";
	public String uri,className;
	public Map<String, String> map = new HashMap<String, String>();
	public UriMeta(String uri){
		this.uri=uri;
	}
	public UriMeta(){
		
	}
	public UriMeta parseUri(){
		StringBuffer sbuf = new StringBuffer(pack);
    	uri = uri.replaceAll("\\.do", "").replaceFirst("^/", "");
		String[] parts = uri.split("\\/");
		if(parts.length>=2){
			sbuf.append(parts[parts.length-2]+".");
		    String[] last = parts[parts.length-1].split(",");
			sbuf.append(Character.toUpperCase(last[0].charAt(0)));
			sbuf.append(last[0].substring(1));
		    if(last.length>1){
		    	for(int i=1;i<last.length;i++){
					map.put("param_"+(i-1), last[i]);
				}
		    }
		}
		this.className=sbuf.toString();
		return this;
	}
	public String getParam(String key){
		return map.get(key);
	}
	public static UriMeta newUriMeta(String uri){
		return new UriMeta(uri).parseUri();
	}
	public static void main(String[] args){
		UriMeta um = UriMeta.newUriMeta("/api/square/adoptlist,my.do");
	    //System.out.println(um.getParam("param_0")+"  =-  "+um.className);
	}
}
